from rest_framework.filters import BaseFilterBackend


# 按添加时间范围搜索
class TimeFilter(BaseFilterBackend):
    def filter_queryset(self, request, queryset, view):
        start_time = request.query_params.get('start_time')
        end_time = request.query_params.get('end_time')
        if start_time and end_time:
            return queryset.filter(date_add__range=(start_time, end_time))
        return queryset
